package my.mylocal.tool;

import java.util.Map;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-6-28
 * Time: 16:52:03
 * To change this template use File | Settings | File Templates.
 */
public class MyLocal {
    private static ThreadLocal<Map<String,Object>> local=new  ThreadLocal<Map<String,Object>>();
    public static void put(String key,Object value){
        Map<String,Object> map=local.get();
        if(map==null){
            map=new HashMap<String,Object>();
            local.set(map);
        }
        map.put(key,value);
    }

    public static Object get(String key){
       Map<String,Object> map=local.get();
       if(map==null) return null;
       return map.get(key);
    }

    public static String[] getLocalKeys(){
        Map<String,Object> map=local.get();
        if(map==null) return new String[0];
        return map.keySet().toArray(new String[0]);
    }

    public static void clear(){
        local.set(null);
    }
}
